var util = require("../util"), MiniProgramLogger = require("../miniProgramLogger"), ARMS_STORAGE_MINIPROGRAM_EAPP_UID_KEY = "ARMS_STORAGE_MINIPROGRAM_EAPP_UID_KEY", EAppLogger = function(e) {
    return MiniProgramLogger.call(this, e), this;
};

EAppLogger.prototype = util.createObject(MiniProgramLogger.prototype), util.ext(MiniProgramLogger._root.dftCon, {
    sendRequest: function(e, t) {
        if ("undefined" != typeof dd && dd && "function" == typeof dd.httpRequest) try {
            var o, r = "GET";
            t && (r = "POST", o = JSON.stringify(t)), dd.httpRequest({
                url: e,
                method: r,
                data: o,
                dataType: "text",
                fail: function(e) {
                    util.warn("[arms] sendRequest fail", e);
                }
            });
        } catch (n) {
            util.warn("[arms] error in conf sendRequest", n);
        }
    },
    getCurrentPage: function() {
        if ("function" == typeof getCurrentPages) try {
            var e = getCurrentPages() || [], t = e[e.length - 1];
            return t && t.route || null;
        } catch (o) {
            util.warn("[arms] error in conf getCurrentPage", o);
        }
    }
}), util.ext(EAppLogger.prototype, {
    constructor: EAppLogger,
    _super: MiniProgramLogger,
    autoSetCommonInfo: function() {
        this.setCommonInfo({
            app: "mini_dd"
        }), this.autoSetSystemInfo(), this.autoSetNetworkType(), this.autoSetUid(), this.autoSetSid();
    },
    autoSetUid: function() {
        var e = this;
        if (e._conf && e._conf.uid) e.setCommonInfo({
            uid: e._conf.uid
        }); else if ("undefined" != typeof dd && dd && "function" == typeof dd.getStorage) try {
            dd.getStorage({
                key: ARMS_STORAGE_MINIPROGRAM_EAPP_UID_KEY,
                success: function(t) {
                    if (t && t.data && "string" == typeof t.data) e.setCommonInfo({
                        uid: t.data
                    }); else if ("function" == typeof dd.setStorage) {
                        var o = util.uu();
                        dd.setStorage({
                            key: ARMS_STORAGE_MINIPROGRAM_EAPP_UID_KEY,
                            data: o,
                            success: function() {
                                e.setCommonInfo({
                                    uid: o
                                });
                            },
                            fail: function(e) {
                                util.warn("[arms] error in setStorage", e);
                            }
                        });
                    }
                },
                fail: function(e) {
                    util.warn("[arms] error in getStorage", e);
                }
            });
        } catch (t) {
            util.warn("[arms] error in autoSetUid", t);
        }
    },
    autoSetSystemInfo: function() {
        var e = this;
        if ("undefined" != typeof dd && dd && "function" == typeof dd.getSystemInfo) try {
            dd.getSystemInfo({
                success: function(t) {
                    t && "object" == typeof t && e.setCommonInfo({
                        sr: (t.screenWidth || 0) + "x" + (t.screenHeight || 0),
                        vp: (t.windowWidth || 0) + "x" + (t.windowHeight || 0),
                        dpr: t.pixelRatio,
                        ul: t.language
                    });
                },
                fail: function(e) {
                    util.warn("[arms] error in getSystemInfo", e);
                }
            });
        } catch (t) {
            util.warn("[arms] error in autoSetSystemInfo", t);
        }
    },
    autoSetNetworkType: function() {
        var e = this;
        if ("undefined" != typeof dd && dd && "function" == typeof dd.getNetworkType) try {
            dd.getNetworkType({
                success: function(t) {
                    t && "string" == typeof t.networkType && e.setCommonInfo({
                        ct: t.networkType
                    });
                },
                fail: function(e) {
                    util.warn("[arms] autoSetNetworkType getNetworkType fail", e);
                }
            });
        } catch (t) {
            util.warn("[arms] error in autoSetNetworkType", t);
        }
    }
}), require("./hook")(EAppLogger);

var behavior = require("./behavior");

"undefined" != typeof dd && dd && behavior(EAppLogger, dd);

var singleton = null, generator = function(e) {
    return singleton || (singleton = new EAppLogger(e || {})), singleton;
};

EAppLogger.createExtraInstance = function(e) {
    e && "object" == typeof e ? (e.disableHook = !0, e.behavior = !1) : e = {
        disableHook: !0,
        behavior: !1
    };
    return new EAppLogger(e);
}, EAppLogger.init = generator, EAppLogger.singleton = generator, EAppLogger._super = MiniProgramLogger, 
EAppLogger._root = MiniProgramLogger._root, MiniProgramLogger.EAppLogger = EAppLogger, 
module.exports = EAppLogger;